﻿using System.Collections.Generic;
using System.Data;
using SdmxMl.Manager;

namespace SdmxMl.Multiplexor
{
    /// <summary>
    /// Class fetching and holding all dirInfo of a registry
    /// </summary>
    public class DirInfoItem
    {
        #region Internal Members

        private ProxyService proxy;
        private DicoDirInfo dicoDir;

        #endregion

        #region Constructor

        public DirInfoItem(ProxyService ProxyService)
        {
            proxy = ProxyService;
            dicoDir = new DicoDirInfo();
        }
        #endregion

        #region public Method

        public DataTable GetDirInfo(SdmxArtefactType arType)
        {
            if (dicoDir.ContainsKey(arType) == false)
            {
                DataSet ds = proxy.DirInfo(arType.ToString());
                if (ds != null && ds.Tables.Count > 0)
                {
                    ds.Tables[0].DefaultView.Sort = "AI, ID, VER ASC";
                    dicoDir[arType] = ds.Tables[0];
                }
            }

            return dicoDir[arType];
        }

        #endregion
    }

    /// <summary>Dictionary holding dirInfo tables for all artefacts type</summary>
    internal class DicoDirInfo : Dictionary<SdmxArtefactType, DataTable>
    {
    }
}
